<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改债权交易')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-transaction-edit" th:object="${crDebtTransaction}">
            <input name="transactionId" th:field="*{transactionId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">主债权人名称：</label>
                <div class="col-sm-8">
                    <input name="creditorName" th:field="*{creditorName}" class="form-control" type="text" disabled>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">主债权人联系电话：</label>
                <div class="col-sm-8">
                    <input name="bondCode" th:field="*{creditorPhone}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">民事判决书（或者仲裁书、调解书）字号：</label>
                <div class="col-sm-8">
                    <input name="bondCode" th:field="*{civilJudgmentFont}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">执行法院：</label>
                <div class="col-sm-8">
                    <input name="debtAmount" th:field="*{compententCourt}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">判决书标的额：</label>
                <div class="col-sm-8">
                    <input name="transferAmount" th:field="*{debtAmount}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">转让金额：</label>
                <div class="col-sm-8">
                    <input name="transferAmount" th:field="*{transferAmount}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">债务人信息：</label>
                <div class="col-sm-8">
                    <table style="font-weight: normal;border: #0a2730" id="debtorPerson">
                        <thead>
                        <tr>
                            <th>姓名/组织机构名称&nbsp;&nbsp;&nbsp; </th>
                            <th>身份证号/社会统一信用代码 &nbsp;&nbsp;&nbsp;</th>
                            <th>身份证/营业执照有效期 &nbsp;&nbsp;&nbsp;</th>
                            <th>债务人所在地址 &nbsp;&nbsp;&nbsp;</th>
                        </tr>
                        </thead>
                        <input id="user_size" type="hidden" value="1">
                        <tbody>
                        <ul th:each="c:${personList}">

                        <tr id="tr_1">
                            <td><li th:text="${c.name}" ></li></td>
                            <td><li th:text="${c.idNum}" ></li></td>
                            <td><li th:text="${c.idValidDate}" ></li></td>
                            <td><li th:text="${c.address}" ></li></td>
                        </tr>
                        </ul>
                        </tbody>
                    </table>

                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">债权人的身份证明材料：</label>
                <div class="col-sm-8">
                    <th:block th:each="image0 : *{#strings.listSplit(idCardBack, ',')}">
                        <img th:src="${image0}" style="height: 150px;">
                    </th:block>
                </div>

            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">民事判决书：</label>
                <div class="col-sm-8">
                    <th:block th:each="image : *{#strings.listSplit(civilJudgement, ',')}">
                        <img th:src="${image}" style="height: 150px;">
                    </th:block>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">委托书：</label>
                <div class="col-sm-8">
                    <img th:src="*{attorneyPower}" style="max-width: 196px">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">承诺书：</label>
                <div class="col-sm-8">
                    <th:block th:each="image : *{#strings.listSplit(statement, ',')}">
                        <img th:src="${image}" style="height: 150px;">
                    </th:block>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">审批状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('approval_status')}" disabled>
                        <input type="radio" th:id="${'approvalStatus_' + dict.dictCode}" name="approvalStatus" th:value="${dict.dictValue}" th:field="*{approvalStatus}" disabled>
                        <label th:for="${'approvalStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">审批时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="approvalTime" th:value="${#dates.format(crDebtTransaction.approvalTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" disabled>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">审批人：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="approver" th:field="*{approver}" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">支付状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('pay_status')}" disabled>
                        <input type="radio" th:id="${'payStatus_' + dict.dictCode}" name="payStatus" th:value="${dict.dictValue}" th:field="*{payStatus}" disabled>
                        <label th:for="${'payStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">支付金额：</label>
                <div class="col-sm-8">
                    <input name="payAmount" th:field="*{payAmount}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">支付时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="payTime" th:value="${#dates.format(crDebtTransaction.payTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" disabled>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/transaction";
        $("#form-transaction-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-transaction-edit').serialize());
            }
        }

        $("input[name='creditorRightsTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='approvalTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='payTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        var files = [[${fileList}]];
        var initPrevConfig = new Array();
        var imgUrls = new Array();
        var fileName = new Array();
        $(files).each(function (index,item) {
            initPrevConfig[index] = {
                caption: item.name, /*文件标题*/
                downloadUrl: item.image,   //这个是显示下载按钮的关键，如果没有此属性，下载按钮是不会显示的。
            };
            imgUrls.push(item.image);
            fileName.push(item.name)
        });
        $("#fileName").val(fileName);
        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            // if(imgUrls != "" && imgUrls != null && imgUrls.length > 0){
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: imgUrls,
                overwriteInitial: false,
                maxFileCount: 1,
                autoReplace: true,
                showDownload: true,
                initialPreviewConfig: initPrevConfig ,
            }).on('fileuploaded', function (event, data, previewId, index) {
                imgUrls.push(data.response.url)
                fileName.push(data.response.name)
                $("input[name='" + event.currentTarget.id + "']").val(imgUrls)
                $("#fileName").val(fileName)
            }).on('fileremoved', function (event, id, index) {
                deleteArr(event, id);
                // $("input[name='" + event.currentTarget.id + "']").val('')
            }).on('filesuccessremove', function(event, id) {
                deleteArray(event, id);
            })
            $(this).fileinput('_initFileActions');
            // }
        });
        function deleteArray(event, id){
            var name = id.split("_")[1];
            var index = fileName.indexOf(name);
            if(imgUrls.length > 0 && fileName.length > 0){
                imgUrls.splice(index,index);
                fileName.splice(index,index);
                $("input[name='" + event.currentTarget.id + "']").val(imgUrls)
                $("#fileName").val(fileName)
            }
        }
        function deleteArr(event, id){
            var ids = id.split("-");
            var index = parseInt(ids[ids.length-1]);
            if(imgUrls.length > 0 && fileName.length > 0){
                imgUrls.splice(index,index+1);
                fileName.splice(index,index+1);
                $("input[name='" + event.currentTarget.id + "']").val(imgUrls)
                $("#fileName").val(fileName)
            }
        }

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    height:194,
                    dialogsInBody: true,
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
                $('#' + this.id).summernote('disable');
            })
        });
    </script>
</body>
</html>